package com.orange.service.impl;

import org.springframework.mail.MailException;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author Emp
 * @projectName: springboot
 * @package: com.orange.service.impl
 * @className: MailServiceImpl
 * @description: TODO
 * @date: 2021/12/7 12:46
 * @version: 1.0
 */
@Service
public class MailServiceImpl implements com.orange.service.MailService {
    @Resource
    private JavaMailSender javaMailSender;

    @Override
    @Async
    public boolean sendMail(String from, String title, String text, String... to){
        try {
            SimpleMailMessage message = new SimpleMailMessage();
            message.setFrom(from);
            message.setTo(to);
            message.setSubject(title);
            message.setText(text);
            javaMailSender.send(message);
            return true;
        } catch (MailException e) {
            e.printStackTrace();
            return false;
        }
    }

}
